package sctu.edu.java.year2016.team03.liyouhong.day20160607.chapter15_3;

import javax.swing.*;
import java.awt.*;

/**
 * Created by Administrator on 2016/6/11 0011.
 * 3.尝试开发一个窗体，在窗体中设计一个进度条，使进度条每次递增滚动。
 */
public class IncreaseRollBar extends JFrame {
    JProgressBar progressBar = new JProgressBar();
    int count = 0;
    Thread thread;

    public IncreaseRollBar() {
        super();
        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                progressBar.setValue(++count);
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        });
        thread.start();
    }

    public static void CreateJFrame(JFrame jf, int width, int height) {

        jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
        jf.setSize(width, height);
        jf.setVisible(true);

    }
    public static void main(String[] args) {
        CreateJFrame(new IncreaseRollBar(),400,400);
    }
}
